home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************************
- FormatAsDOSDisk.c
-
- Written by Jim Luther with some modifications by Virginia McCulloh
- Apple Developer Technical Support
- August, 1996, Cupertino, CA
- Copyright 1996, Apple Computer, Inc.
-
- This snippet demonstrates how to use the newer Disk Initialization
- Package calls DIXFormat() and DIXZero() to format a floppy disk as
- a DOS disk. DIXFormat, DIXZero, and DIReformat are documented in
- the IM:Files Errata Tech Note.
-
- Please note this snippet does not provide any prompts. It merely takes
- the floppy in the first floppy drive and reformats it as a DOS disk with
- the name "MS-DOS Disk". This purpose of this snippet is to demonstrate
- the newer API.
-
- This runs under Metrowerks CodeWarrior 8 with the Universal
- Interfaces 2.1 from ETO #18.
-
- /*****************************************************************************/
-
- #include <Gestalt.h>
- #include <FSM.h>
- #include <DiskInit.h>
-
- /******************************************************************************/
-
- /*
- ** Prototypes and inlines for newer Disk INIT calls
- */
-
- extern pascal OSErr DIXFormat(short drvNum, Boolean fmtFlag, unsigned long fmtArg,
- unsigned long *actSize)
- THREEWORDINLINE(0x700C, 0x3F00, 0xA9E9);
-
- extern pascal OSErr DIXZero(short drvNum, ConstStr255Param volName, short fsid,
- short mediaStatus, short volTypeSelector,
- unsigned long volSize, void *extendedInfoPtr)
- THREEWORDINLINE(0x700E, 0x3F00, 0xA9E9);
-
- extern pascal OSErr DIReformat(short drvNum, short fsid, ConstStr255Param volName,
- ConstStr255Param msgText)
- THREEWORDINLINE(0x7010, 0x3F00, 0xA9E9);
-
- /*
- ** Prototypes for functions here
- */
-
- Boolean HasExtendedDIFunctions(void);
- OSErr FormatAsDOS(short driveNumber, ConstStr255Param volName);
-
-
- /******************************************************************************/
-
- /*
- ** See if new extended Disk Init package is available
- */
- Boolean HasExtendedDIFunctions(void)
- {
- long response;
-
- if ( Gestalt(gestaltFSAttr, &response) == noErr )
- return ( (response & (1L << gestaltHasExtendedDiskInit)) != 0 );
- else
- return ( false );
- }
-
- /******************************************************************************/
-
- /*
- ** Format the unmounted floppy disk specified by driveNum as an MS-DOS disk.
- */
- OSErr FormatAsDOS(short driveNumber, ConstStr255Param volName)
- {
- enum
- {
- kMacPCExchangeFSID = 0x4953 /* file system ID of Macintosh PC Exchange's
- MS-DOS file system (see "Guide-File System Mgr"
- on MacOS SDK in File System Manager SDK).*/
- };
- OSErr result;
- unsigned long actSize;
-
- /*
- ** Format the disk. Passing false for fmtFlag and 1440 for fmtArg tells
- ** the Disk Init package to format the disk with 1440 blocks (720K MFM) or
- ** if 1440 blocks isn't available (because the disk is a high density disk),
- ** to format the disk with the smallest size that's greater than 1440 blocks
- ** (which will be 2880 blocks (1440K MFM)).
- */
- result = DIXFormat(driveNumber, false, 1440, &actSize);
- if ( result == noErr )
- {
- /* Verify the disk */
- result = DIVerify(driveNumber);
-
- /*
- ** The result of DIVerify is passed to DIXZero in the mediaStatus parameter.
- ** If mediaStatus is noErr, then the disk is simply initialized. If
- ** mediaStatus is not noErr, then DIXZero attempts to spare any bad blocks
- ** if the file system supports that. MS-DOS disks can be bad block spared.
- */
- result = DIXZero(driveNumber, volName, kMacPCExchangeFSID, result,
- 0, actSize, NULL);
- }
-
- return ( result );
- }
-
- /******************************************************************************/
-
- /* Test code */
- void main(void)
- {
- short driveNumber = 1; /* hard coded to use the 1st floppy drive */
- OSErr result;
- Str255 volName = "\pMS-DOS Disk";
-
- if ( HasExtendedDIFunctions() )
- {
- result = UnmountVol(NULL, driveNumber); /* unmount disk in the drive (if it was mounted) */
- result = FormatAsDOS(driveNumber, volName);
- }
- }